public class StackTasks {
    public static void main(String[] args) {
        StackWithMin<Integer> intStack = new StackWithMin<Integer>(new Integer[]{2, 3, 9, -20, 1, 0, 4, 5, -7, -88});
        printTheStack(intStack);
        System.out.println("Current minimum: " + intStack.getMinimum());
        System.out.println("Pop() -->   " + intStack.pop());
        System.out.println("Current minimum: " + intStack.getMinimum());
        System.out.println();
        System.out.println();
        System.out.println();

        MultiStack<Integer> multiStack = new MultiStack<Integer>(3);
        multiStack.push(1);
        System.out.println("After the first element insertion: " + multiStack);
        multiStack.push(3);
        multiStack.push(2);
        multiStack.push(4);
        System.out.println("Now we have two stacks inside: " + multiStack);
        multiStack.pop();
        multiStack.pop();
        System.out.println("Oh, no. One stack, again: " + multiStack);

        HanoiTower<Integer> hanoiTower = new HanoiTower<Integer>(9, 8, 7, 6, 5, 4, 3, 2, 1);
        System.out.println("The Hanoi towers are:  " + hanoiTower);
        hanoiTower.solveTheProblem();
        System.out.println("And now here are them: " + hanoiTower);

        System.out.print("What about sorting a stack? ");
        System.out.println();
        Stack<Integer> stack = new StackImpl<Integer>(new Integer[]{2, 3, 0, -20, 1, -5});
        printTheStack(stack);
        stack = sortTheStack(stack);
        printTheStack(stack);
    }

    private static void printTheStack(Stack<Integer> stack) {
        StringBuilder sb = new StringBuilder("[");
        int sizeOfStack = stack.getNumberOfElements();
        for (int i = 0; i < sizeOfStack; i++) {
            int value = stack.getElementAt(i);
            sb.append(value);
            if (i < sizeOfStack - 1) {
                sb.append("--> ");
            }
        }
        sb.append("]");
        System.out.println(sb);
    }

    /*
        3.6 Write a program to sort a stack in ascending order (with biggest items on top).
        You may use at most one additional stack to hold items, but you may not copy
        the elements into any other data structure (such as an array). The stack supports
        the following operations: push, pop, peek, and isEmpty.
    */
    public static Stack<Integer> sortTheStack(Stack<Integer> s) {
        Stack<Integer> s2 = new StackImpl<Integer>();
        while (!s.isEmpty()) {
            Integer top = s.pop();
            while (!s2.isEmpty() && (s2.peek() > top)) {
                s.push(s2.pop());
            }
            s2.push(top);
        }
        return s2;
    }

    /*
        3.7 An animal shelter holds only dogs and cats, and operates on a strictly "first in, first out" basis.
        People must adopt either the "oldest" (based on arrival time) of all animals at the shelter, or they can
        select whether they would prefer a dog or a cat (and will receive the oldest animal of that type).
        They cannot select which specificanimal they would like. Create the data structures to maintain this system
        and implement operations such as enqueue, dequeueAny, dequeueDog and dequeueCat.You may use the built-in LinkedList data structure.
     */
    // Two linked lists and a order counter.
}
